import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';

export type DefaultConfig = PowerPartial<EggAppConfig>;

export default (appInfo: EggAppInfo) => {
  const config = {} as DefaultConfig;

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1623061683568_5324';

  config.token = {
    secretKey: 'nXy82n2OihhHIhijiJInNjNI',
    duration: 7200
  }

  // add your config here
  config.middleware = [
    'tokenVerifyMiddleware'
  ];

  config.midwayFeature = {
    // true 代表使用 midway logger
    // false 或者为空代表使用 egg-logger
    replaceEggLogger: true,
  };

  config.security = {
    csrf: {
      enable: false,
    },
    domainWhiteList: [ 'http://monit.simfeng.com' ,'http://localhost:8081'],
  };

  config.cors = {
    origin:'http://monit.simfeng.com',
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH'
  };

  // ---- MYSQL ----
  // config.sequelize = {
  //   host: 'gz-cdb-b1z3v79l.sql.tencentcdb.com',
  //   port: 58980,
  //   dialect: 'mysql',
  //   database: 'game',
  //   username: 'root', // 用户名
  //   password: 'b88888888@', // 用户密码
  //   timezone: '+08:00', // 保存为本地时区
  // }

  // config.sequelize = {
  //   host: 'gz-cdb-coxjfb65.sql.tencentcdb.com',
  //   port: 58731,
  //   dialect: 'mysql',
  //   database: 'simfeng',
  //   username: 'root', // 用户名
  //   password: 'b88888888@', // 用户密码
  //   timezone: '+08:00', // 保存为本地时区
  // }

  /**
 * 单数据库实例
 */
  config.orm = {
    type: 'mysql',
    host: 'gz-cdb-coxjfb65.sql.tencentcdb.com',
    port: 58731,
    username: 'root',
    password: 'b88888888@',
    database: 'simfeng',
    synchronize: true,   // 如果第一次使用，不存在表，有同步的需求可以写 true
    logging: true,
    timezone: '+08:00', // 保存为本地时区
  };

  // `npx mdl-gen-midway -h gz-cdb-coxjfb65.sql.tencentcdb.com -p 58731 -d simfeng -u root -x b88888888@ -e mysql --noConfig --case-property none`

  config.tencentcloudSms = {
    secretID: 'AKIDWjplYmxX5OPBIB9EO2SDhxzlERSIYzSq',
    secretKEY: 'KZeT4QTGn7F3biaDgtte9OOAhyzsTqxp',
  };

  return config;
};
